Unit FormClassTree;

Interface

Uses
  Windows, Messages, SysUtils, DB, ADODB, StdCtrls, Buttons, Mask, DBCtrls,
  Controls, ExtCtrls, Classes, fcTreeView, Graphics, Forms, Dialogs,
  ComCtrls, ImgList, FormClass, ActnList;

Type
  TfmFormClassTree = Class(TfmFormClass)
  Private
    Node, NodeIlk : TfcTreeNode;
    DNode : Array[0..4] Of TfcTreeNode;
    DKod, EKod : Array[0..4] Of String;
    ItemString : String;
    { Private declarations }
  Public
    { Public declarations }
    Procedure PrepareTreeView(dxTree : TfcTreeView; gItemString : String; gItemAdi : String;
      ImageIndex : Smallint = -1; gEskiKod : String = ''; gCheck : Boolean = True; gRadio : Boolean = False;
      SelectedImageIndex : Smallint = -1; StateImageIndex : Smallint = -1; Visible : Boolean = True);Virtual;

  End;

Var
  fmFormClassTree : TfmFormClassTree;

Implementation

Uses UnitOrtak, UnitTeknik;
{$R *.dfm}

Procedure TfmFormClassTree.PrepareTreeView(dxTree : TfcTreeView; gItemString : String; gItemAdi : String;
  ImageIndex : Smallint = -1; gEskiKod : String = ''; gCheck : Boolean = True; gRadio : Boolean = False;
  SelectedImageIndex : Smallint = -1; StateImageIndex : Smallint = -1; Visible : Boolean = True);
Var
  i : Integer;
  gItemKod1 : String;
  gItemKod2 : String;
  gItemKod3 : String;
  gItemKod4 : String;
  gItemKod5 : String;

  Function AddChilds(Node : TfcTreeNode; StringData : String; Etiket : String) : TfcTreeNode;
  Var
    N : TfcTreeNode;
  Begin
    N := dxTree.Items.AddChild(Node, Etiket);
    StringData := KarekterCikar(StringData, '_');

    N.SelectedIndex := SelectedImageIndex;
    N.ImageIndex := ImageIndex;
    N.StateIndex := StateImageIndex;

    If gCheck Then
    Begin
      N.StateIndex := -1;
      N.CheckboxType := tvctCheckbox;
      N.Checked := False;
    End;

    N.StringData := StringData;
    N.StringData2 := gEskiKod;          //gItemAdi;
    If gRadio Then
    Begin
      N.StateIndex := -1;
      N.CheckboxType := tvctRadioGroup;
      N.Checked := False;
    End;
    Result := N;
  End;

Begin
  If (SelectedImageIndex < 0) Then
    SelectedImageIndex := ImageIndex;

  dxTree.OnToggleCheckbox := Nil;

  gItemKod1 := Copy(Trim(gItemString), 4, 2);
  gItemKod2 := Copy(Trim(gItemString), 7, 2);
  gItemKod3 := Copy(Trim(gItemString), 10, 2);
  gItemKod4 := Copy(Trim(gItemString), 13, 2);
  gItemKod5 := Copy(Trim(gItemString), 16, 2);

  DKod[0] := gItemKod1;
  DKod[1] := gItemKod2;
  DKod[2] := gItemKod3;
  DKod[3] := gItemKod4;
  DKod[4] := gItemKod5;
  ItemString := gItemString;

  If CharCount('_', gItemString) < 1 Then
    NodeIlk := AddChilds(Nil, gItemString, gItemAdi)
  Else
  Begin
    For i := Low(DKod) To High(DKod) Do
    Begin
      If DKod[i] <> EKod[i] Then
        Break;
    End;

    Case i Of
      0 :
        Begin
          Node := AddChilds(NodeIlk, ItemString, gItemAdi);
          DNode[0] := Node;
        End;
      1 :
        Begin
          Node := AddChilds(DNode[0], ItemString, gItemAdi);
          DNode[1] := Node;
        End;
      2 :
        Begin
          Node := AddChilds(DNode[1], ItemString, gItemAdi);
          DNode[2] := Node;
        End;
      3 :
        Begin
          Node := AddChilds(DNode[2], ItemString, gItemAdi);
          DNode[3] := Node;
        End;
      4 :
        Begin
          Node := AddChilds(DNode[3], ItemString, gItemAdi);
          DNode[4] := Node;
        End;
    End;
  End;

  EKod[0] := gItemKod1;
  EKod[1] := gItemKod2;
  EKod[2] := gItemKod3;
  EKod[3] := gItemKod4;
  EKod[4] := gItemKod5;
End;

End.

